import { createHashRouter, Navigate } from "react-router-dom";
//一级路由
import Login from "../pages/Login";
import Layout from "../pages/Layout/index.jsx";
// 二级路由
// import Account from "../pages/Account/index.jsx";
// import Goods from "../pages/Goods";
import Home from "../pages/Home";
import Order from "../pages/Order";
// import SalesList from "../pages/SalesList";
import Store from "../pages/Store";

// //二级路由
//商品列表二级路由
import GoodsAdd from "../pages/Goods/GoodsAdd";
import GoodsList from "../pages/Goods/GoodsList";
import GoodsSort from "../pages/Goods/GoodsSort";
//账号列表二级路由
import Add from "../pages/Account/Add";
import List from "../pages/Account/List";
import Update from "../pages/Account/Update";
import UserCenter from "../pages/Account/UserCenter";
//销售统计二级路由
import Form from "../pages/SalesList/Form";
import Products from "../pages/SalesList/Products";

const routes = [
  {
    path: "/",
    element: <Navigate to="/login" />,
  },

  {
    path: "/login",
    element: <Login />,
  },

  {
    path: "/home",
    // loader:()=>{return{title:'系统首页'}},
    loader: () => ({ title: "系统首页",key: "/home" }),

    element: <Layout />,
    children: [
      {
        loader:()=> ({key: "/home"}),
        index: true,
        element: <Home />,
      },
    ],
  },
  {
    path: "/account",
    loader: () => {
      return { title: "账号管理", key:'/account1' };
    },

    element: <Layout />,
    children: [
      {
        index: true,
        loader: () => ({ title: "账号列表",key:'/account' }),
        element: <List />,
      },
      {
        loader: () => ({ title: "添加账号" ,key:'/account/add'}),
        path: "/account/add",
        element: <Add />,
      },
      {
        loader: () => ({ title: "修改密码",key:'/account/update'}),
        path: "/account/update",
        element: <Update />,
      },
      {
        loader: () => ({ title: "个人中心",key:'/account/usercenter' }),
        path: "/account/usercenter",
        element: <UserCenter />,
      },
    ],
  },
  {
    path: "/order",
    loader: () => ({ title: "订单管理",key:'/order' }),

    element: <Layout />,
    children: [
      {
        loader:()=>({key:'/order'}),
        index: true,
        element: <Order />,
      },
    ],
  },
  {
    path: "/goods",
    loader: () => ({ title: "商品管理",  key:'/goods1'}),
    element: <Layout />,
    children: [
      {
        index: true,
        loader: () => ({ title: "商品列表", key:'/goods'}),
        element: <GoodsList />,
      },
      {
        loader: () => ({ title: "添加商品" ,key:'/goods/goodsadd'}),
        path: "/goods/goodsadd",
        element: <GoodsAdd />,
      },
      {
        loader: () => ({ title: "商品分类",key:'/goods/goodssort' }),
        path: "/goods/goodssort",
        element: <GoodsSort />,
      },
    ],
  },
  {
    path: "/store",
    loader: () => ({ title: "店铺管理",key:'/store' }),

    element: <Layout />,
    children: [
      {
        loader:()=>({key:'/store'}),
        index: true,
        element: <Store />,
      },
    ],
  },

  {
    path: "/saleslist",
    loader: () => ({ title: "统计数据" ,key:'/saleslist1'}),
    element: <Layout />,

    children: [
      {
        index: true,
        loader: () => ({ title: "商品统计",key:'/saleslist'}),
        element: <Products />,
      },
      {
        loader: () => ({ title: "订单统计" ,key:'/saleslist/form'}),
        path: "/saleslist/form",
        element: <Form />,
      },
    ],
  },

  {
    path: "*",
    element: <Error />,
  },
];

const router = createHashRouter(routes);

export default router;
